﻿@using King.Box.Models.Db.Sys;
@model Sys_Menu

<div class="ibox">
    <div class="ibox-title">
        <div class="btn-group hidden-xs" role="group">
            <button type="button" class="btn btn-outline btn-default save">
                <i class="glyphicon glyphicon-save" aria-hidden="true"></i>保存
            </button>
            <button type="button" class="btn btn-outline btn-default close-layer">
                <i class="glyphicon glyphicon-off" aria-hidden="true"></i>关闭
            </button>
        </div>
    </div>
    <div class="ibox-content">
        <div>
            @using (Html.BeginForm("AddMenu", "Sys", FormMethod.Post, new { @class = "form-horizontal", @role = "form", @id = "mainForm" }))
            {
                <div class="form-group">
                    <div class="col-md-6 col-sm-6">
                        <label class="control-label">ID</label>
                        @Html.TextBoxFor(model => model.Id, new { @class = "form-control", @readonly = true })
                    </div>
                    <div class="col-md-6 col-sm-6">
                        <label class="control-label">菜单名称</label>
                        @Html.TextBoxFor(model => model.Name, new { @class = "form-control" })
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-6 col-sm-6">
                        <label class="control-label">菜单级别</label>
                        @Html.DropDownListFor(model => model.Level, ViewData.FirstOrDefault(x => x.Key.Equals("LevelData")).Value as IEnumerable<SelectListItem>, new { @class = "form-control level" })
                    </div>
                    <div class="col-md-6 col-sm-6">
                        <label class="control-label">父级</label>
                        @Html.DropDownListFor(model => model.ParentId, ViewData.FirstOrDefault(x => x.Key.Equals("ParentData")).Value as IEnumerable<SelectListItem>, new { @class = "form-control parent" })
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-6 col-sm-6">
                        <label class="control-label">链接</label>
                        @Html.TextBoxFor(model => model.Url, new { @class = "form-control url" })
                    </div>
                    <div class="col-md-6 col-sm-6">
                        <label class="control-label">图标</label>
                        @Html.TextBoxFor(model => model.Icon, new { @class = "form-control" })
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-6 col-sm-6">
                        <label class="control-label">排序</label>
                        @Html.TextBoxFor(model => model.Sort, new { @class = "form-control" })
                    </div>
                    <div class="col-md-3 col-sm-3">
                        <label class="control-label">创建时间</label>
                        @Html.TextBoxFor(model => model.CreateTime, new { @class = "form-control", @readonly = "true" })
                    </div>
                    <div class="col-md-3 col-sm-3">
                        <label class="control-label">最后更新时间</label>
                        @Html.TextBoxFor(model => model.UpdateTime, new { @class = "form-control", @readonly = "true" })
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-12 col-sm-12">
                        <label class="control-label">描述</label>
                        @Html.TextAreaFor(model => model.Description, new { @class = "form-control" })
                    </div>
                </div>}
        </div>
    </div>
</div>

@section Js{
    <script type="text/javascript">
        $(function () {
            event.init();
        });

        var event = {
            height: function () {
                return $(window).innerHeight() * 80 / 100 + "px";
            },
            weight: function () {
                return $(window).innerWidth() * 80 / 100 + "px";
            },
            init: function () {
                $(".level").change(function () {
                    $(".parent").attr('disabled', true);
                    $(".url").attr('readonly', false);

                    if (parseInt($(".level").val()) == 1) {
                        $(".url").attr('readonly', true);
                    } else if (parseInt($(".level").val()) > 1) {
                        $(".parent").attr('disabled', false);
                    }
                });

                $(".save").click(function () {
                    $.post("/Sys/SysMenuEdit", $("#mainForm").serializeArray(),
                    function (res) {
                        if (res.Result) {
                            swal({
                                title: "成功",
                                text: "保存成功",
                                type: "success",
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "确定",
                                closeOnConfirm: false
                            },
				             function () {
				                 $(".close-layer").trigger('click');
				             });
                        }
                        else
                            swal("出错了..", res.Message, "error");
                    });
                });

                $(".level").trigger('change');
            }
        };
    </script>
}
